var sz_WeChatShareService = {
    config: function (appId) {
        if (typeof wx !== 'object') {
            throw new Error('微信对象为null');
        }
        if (wx.cambioInit && wx.cambioInit === true) {
            //alert("cambioInit == true" + window.location.href.split('#')[0]);
            //wx.ready(function () {
            //    //wx.cambioInit = true;
            //    resolve(wx);
            //});
        } else {
            const params = {
                url: window.location.href.split('#')[0],
                appId: appId
            };
            sz_WeChatResource.jsSdkConfig(params, function (config) {
                if (typeof wx !== 'object') {
                    console.log('微信对象为null');
                    throw new Error('微信对象为null');
                }
                wx.config({
                    debug: false,
                    appId: config.appId,
                    timestamp: config.timestamp,
                    nonceStr: config.nonceStr,
                    signature: config.signature,
                    jsApiList: config.jsApiList
                });
                wx.ready(function () {
                    //sessionStorage.setItem('reloadCount','1');
                    //wx.cambioInit = true;
                    if (wx.successReady) {
                        wx.successReady();
                    }
                });
                wx.error(function (res) {
                    // config信息验证失败会执行error函数，如签名过期导致验证失败，具体错误信息可以打开config的debug模式查看，也可以在返回的res参数中查看，对于SPA可以在这里更新签名。
                    var ua = navigator.userAgent.toLowerCase();
                    if (ua.indexOf("micromessenger") > -1) {
                        if (!sessionStorage.getItem('reloadCount')) {
                            sessionStorage.setItem('reloadCount', '1');
                        }
                        if (sessionStorage.getItem('reloadCount') === '1') {
                            sessionStorage.setItem('reloadCount', parseInt(sessionStorage.getItem('reloadCount')) + 1 + '');
                            // window.location.reload();
                        }
                    }
                });
            });
        }
    },

    share: function (wx, shareUri, shareDesc, shareImageUri, shareTitle) {
        // if (!SessionStorage.getItem('itemId')) {
        //     return;
        // }
        // const shareTitle = SessionStorage.getItem('studyMapName');// 分享标题
        //var shareTitle = '测试标题';
        // var shareDesc = SessionStorage.getItem('studyMapRemark');// 分享描述
        // var imageUrl = "http://atb.mb-test.augcloud.cn/static/logo.png";
        // const params = {
        //     userId: SessionStorage.getItem('userId'),
        //     productId: SessionStorage.getItem('itemId')
        // };
        // this.qrCodeResource.atbShare(params, function (result) {
        //     var shareLink = result.value;
        wx.onMenuShareTimeline({
            title: shareTitle,
            link: shareUri,
            imgUrl: shareImageUri,
            //type: '', // 分享类型,music、video或link，不填默认为link
            //dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
            success: function () {
                //alert('success');
            },
            cancel: function (reason) {
                //CambioLog.error("cancel");
                //alert('cancel');
            },
            fail: function (res) {
                alert('异常' + JSON.stringify(res));
                //CambioLog.error('wx.onMenuShareTimeline:fail: ' + JSON.stringify(res));
            }
        });
        wx.onMenuShareAppMessage({
            title: shareTitle,
            desc: shareDesc,
            link: shareUri,
            imgUrl: shareImageUri,
            //type: '', // 分享类型,music、video或link，不填默认为link
            //dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
            success: function () {
                //alert('success');
            },
            cancel: function (reason) {
                //CambioLog.error("cancel");
                //alert('cancel');
            },
            fail: function (res) {
                alert('异常' + JSON.stringify(res));
                //CambioLog.error('wx.onMenuShareTimeline:fail: ' + JSON.stringify(res));
            }
        });
        wx.onMenuShareQQ({
            title: shareTitle,
            desc: shareDesc,
            link: shareUri,
            imgUrl: shareImageUri,
            success: function () {
                //CambioLog.debug("success");
            },
            cancel: function () {
                //CambioLog.error("cancel");
            }
        });
        wx.onMenuShareWeibo({
            title: shareTitle,
            desc: shareDesc,
            link: shareUri,
            imgUrl: shareImageUri,
            success: function () {
                //CambioLog.debug("success");
            },
            cancel: function () {
                //CambioLog.error("cancel");
            }
        });
        // });
    }
}